import mockApi from "@/api/mockApi";
import type {ChargeForm} from '@/types/req/chargeForm'
import type {ChargeQueryForm} from '@/types/req/chargeQueryForm'
import type {Charge} from '@/types/resp/charge'
import type {Response} from '@/types/response'
import type {Result} from '@/types/result'
import type {Page} from "@/types/page";
import dayjs from "dayjs";

export default class chargeApi {
  static charges: Charge[] = [
    {id: 1, buildingId: 1, buildingName: '北区1栋', roomId: 1, roomNumber: '301', chargeType: 40, billingCycle: '月度', billingStartDate: dayjs('2024-01-01'), billingEndDate: dayjs('2024-01-31'), amount: 32.54, lateFee: 0, dueDate: dayjs('2020-01-31'), paymentStatus: 10, createTime: '2024-01-01 12:12:12', modifyTime: '2024-02-02 13:13:13'},
    {id: 2, buildingId: 2, buildingName: '北区1栋', roomId: 2, roomNumber: '402', chargeType: 20, billingCycle: '月度', billingStartDate: dayjs('2024-02-01'), billingEndDate: dayjs('2024-02-29'), amount: 43.54, lateFee: 2.36, dueDate: dayjs('2021-02-29'), paymentDate: dayjs('2022-03-15'), paymentStatus: 20, createTime: '2024-02-02 12:12:12', modifyTime: '2024-03-03 13:13:13'},
    {id: 3, buildingId: 3, buildingName: '南区1栋', roomId: 3, roomNumber: '503', chargeType: 30, billingCycle: '年度', billingStartDate: dayjs('2024-03-01'), billingEndDate: dayjs('2024-03-31'), amount: 54.54, lateFee: 0, dueDate: dayjs('2022-03-31'), paymentStatus: 90, createTime: '2024-03-03 12:12:12', modifyTime: '2024-04-04 13:13:13'},
    {id: 4, buildingId: 4, buildingName: '南区2栋', roomId: 4, roomNumber: '604', chargeType: 10, billingCycle: '月度', billingStartDate: dayjs('2024-04-01'), billingEndDate: dayjs('2024-04-30'), amount: 65.54, lateFee: 4.58, dueDate: dayjs('2023-04-30'), paymentDate: dayjs('2023-05-27'), paymentStatus: 20, createTime: '2024-04-04 12:12:12', modifyTime: '2024-05-05 13:13:13'},
    {id: 5, buildingId: 5, buildingName: '东区1栋', roomId: 5, roomNumber: '604', chargeType: 20, billingCycle: '年度', billingStartDate: dayjs('2024-04-01'), billingEndDate: dayjs('2024-04-30'), amount: 65.54, lateFee: 4.58, dueDate: dayjs('2022-04-30'), paymentDate: dayjs('2021-05-27'), paymentStatus: 10, createTime: '2024-04-04 12:12:12', modifyTime: '2024-05-05 13:13:13'},
    {id: 6, buildingId: 6, buildingName: '东区2栋', roomId: 6, roomNumber: '604', chargeType: 30, billingCycle: '月度', billingStartDate: dayjs('2024-04-01'), billingEndDate: dayjs('2024-04-30'), amount: 65.54, lateFee: 4.58, dueDate: dayjs('2021-04-30'), paymentDate: dayjs('2020-05-27'), paymentStatus: 20, createTime: '2024-04-04 12:12:12', modifyTime: '2024-05-05 13:13:13'}
  ]

  static async save (chargeForm: ChargeForm): Promise<Result<void>> {
    console.log('chargeApi save params', chargeForm)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }

  static async find (chargeQueryForm: ChargeQueryForm): Promise<Result<Page<Charge>>> {
    console.log('chargeApi find params', chargeQueryForm)
    const response: Response<Page<object>> = await mockApi.queryPageSuccessfully(chargeApi.charges)
    return response.data
  }

  static async findById (id: number): Promise<Result<Charge>> {
    console.log('chargeApi findById id', id)
    let target = {}
    for (const a of chargeApi.charges) {
      if (a.id === id) {
        target = a
      }
    }
    const response: Response<Charge> = await mockApi.operateSuccessfullyWithData(target)
    return response.data
  }

  static async del (id: number): Promise<Result<void>> {
    console.log('chargeApi del id', id)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }
}
